from fastapi import Request, Response
from fastapi.routing import APIRoute
from afast_core.core_libs.classy_apirouter.group_router import RestInjectForAPIRouter, RestInjectForDocRouter
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from afast_core.core_libs.classy_apirouter import IHookGroupBaseController
from afast_core.core_libs.classy_apirouter import get, post
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.department.controllers.add import \
    SystemDepartmentAddController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.department.controllers.delete import \
    SystemDepartmentDeleteController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.department.controllers.list_all import \
    SystemDepartmentQueryController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.department.controllers.tree_list import \
    SystemDepartmentTreeListyController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.department.controllers.update import \
    SystemDepartmentUpdateController


#  tags=['测试类装饰器依赖项']

@RestInjectForAPIRouter(prefix='/department')
@RestInjectForDocRouter(tags=['后台系统-部门管理模块'])
class AGroupAPIRouterBuilder(IHookGroupBaseController):
    # 定义公共全局的可用的服务，通过request对象进行透传当前的self

    async def before_request(self, curr_apiroute: APIRoute, request: Request) -> None:
        """如果需要修改请求信息，可直接重写此方法"""
        pass
        request.state.api_router_builder = self
        # 如果存在body对象的，在这里读取一下，以备后续的使用
        request.state.schema_param_body = await request.body()
        print("request.state.schema_param_body ", request.state.schema_param_body)

    async def after_request(self, request: Request, response: Response) -> None:
        """请求后的处理"""
        pass

    @get("/listAll", summary='部门模块-部门列表信息获取')
    def admin_department_list_all(self, controller: IBaseController = SystemDepartmentQueryController):
        return controller.sync_response()

    @get("/treeList", summary='部门单模块-菜单列表信息获取')
    def admin_department_treeList(self, controller: IBaseController = SystemDepartmentTreeListyController):
        return controller.sync_response()

    @post("/update", summary='部门模块-菜单列表信息获取')
    def admin_department_update(self, controller: IBaseController = SystemDepartmentUpdateController):
        return controller.sync_response()

    @post("/add", summary='部门模块-添加部门')
    def admin_department_add(self, controller: IBaseController = SystemDepartmentAddController):
        return controller.sync_response()

    @get("/delete/{id}", summary='部门单模块-删除部门')
    def admin_department_delete(self, controller: IBaseController = SystemDepartmentDeleteController):
        return controller.sync_response()
